package com.qnbc.mystery.service.impl;

import java.util.Date;
import java.util.List;

import com.qnbc.mystery.pojo.domain.ProComment;
import com.qnbc.mystery.pojo.domain.User;
import com.qnbc.mystery.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qnbc.mystery.mapper.ProCommentMapper;
import com.qnbc.mystery.service.IProCommentService;

/**
 * 商品评论Service业务层处理
 *
 * @author guzj
 * @date 2024-01-24
 */
@Service
public class ProCommentServiceImpl implements IProCommentService {
    @Autowired
    private ProCommentMapper proCommentMapper;

    /**
     * 查询商品评论
     *
     * @param id 商品评论主键
     * @return 商品评论
     */
    @Override
    public ProComment selectProCommentById(Long id) {
        return proCommentMapper.selectProCommentById(id);
    }

    /**
     * 查询商品评论列表
     *
     * @param proComment 商品评论
     * @return 商品评论
     */
    @Override
    public List<ProComment> selectProCommentList(ProComment proComment) {
        return proCommentMapper.selectProCommentList(proComment);
    }

    /**
     * 新增商品评论
     *
     * @param proComment 商品评论
     * @return 结果
     */
    @Override
    public int insertProComment(ProComment proComment) {
        User currentUser = TokenUtils.getCurrentUser();
        proComment.setAddtime(new Date());
        proComment.setUserid(Long.valueOf(currentUser.getId()));


        return proCommentMapper.insertProComment(proComment);
    }

    /**
     * 修改商品评论
     *
     * @param proComment 商品评论
     * @return 结果
     */
    @Override
    public int updateProComment(ProComment proComment) {
        return proCommentMapper.updateProComment(proComment);
    }

    /**
     * 批量删除商品评论
     *
     * @param ids 需要删除的商品评论主键
     * @return 结果
     */
    @Override
    public int deleteProCommentByIds(Long[] ids) {
        return proCommentMapper.deleteProCommentByIds(ids);
    }

    /**
     * 删除商品评论信息
     *
     * @param id 商品评论主键
     * @return 结果
     */
    @Override
    public int deleteProCommentById(Long id) {
        return proCommentMapper.deleteProCommentById(id);
    }
}
